<?php
/**
 * Created by YuanXiShop.
 * User: YuanXi
 * Date: 2021/6/3 0003
 * Time: 1:26
 */

namespace admin;


use models\BaseDao;

class Payway extends Admin
{
    function __construct()
    {
        parent::__construct();
        $this->assign('menumark','payway');
    }
    function index()
    {
        //获取数据库操作对象
        $db = new BaseDao();
        //获取全部支付方式，并按ord排序
        $data = $db->select('payway','*',['ORDER'=>['ord'=>'ASC','id'=>'DESC']]);
        //将数据分配给模板
        $this->assign('data',$data);
        //标题
        $this->assign('title','支付方式');
        //输出模板
        $this->display('payway/index');
    }
    function mod($id)
    {
        $db = new BaseDao();

        $data = $db->get('payway','*',['id'=>$id]);

        $this->assign($data);

        $this->assign('qt',['停用','启用']);

        $this->assign('title','修改支付方式');

        $this->display('payway/mod');
    }
    function doupdate()
    {
        $id = $_POST['id'];

        unset($_POST['id']);

        $db = new BaseDao();

        if($db->update('payway',$_POST,['id'=>$id])){
            $this->success('/admin/payway','修改成功！');
        }else{
            $this->error('/admin/payway/mod/'.$id,'修改失败！');
        }
    }
    function order()
    {
        $db = new BaseDao();
        $num = 0;
        foreach ($_POST['ord'] as $id=>$ord){
            $num += $db->update('payway',['ord'=>$ord],['id'=>$id]);
        }
        if($num > 0){
            $this->success('/admin/payway','重新排序成功！');
        }else{
            $this->error('/admin/payway','重新排序失败！');
        }
    }
}